package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:String相关方法
 * User: LianBao
 * Date: 2024-03-10
 * Time:
 */
public class Test1 {


    public static void main(String[] args) {
        String str1 = "abcd";
        String str2 = "ABCD";
        System.out.println(str1.equalsIgnoreCase(str2));//忽略大小写,判断是否相同

    }

    public static void main3(String[] args) {
        String str1 = "abcd";
        String str2 = "abcd";
        System.out.println(str1 == str2);//true
        String str3 = new String("hello");
        String str4 = new String("hello");
        System.out.println(str3 == str4);//false
        /*
         * 只要是双引号引起来的字符串常量,会存储在字符串常量池中
         * 1.先检查常量池中有没有这个字符串
         * 2.如果没有就存进去
         * 3.如果没有,就不重复存储了,取出现有的对象即可
         * */
        System.out.println(str1.equals(str2));//比较字符串是否相同
    }

    public static void main2(String[] args) {
        String str1 = "abc";
        String str2 = "";
        System.out.println(str1.length());//求字符串长度
        System.out.println(str2.length());
        System.out.println(str2.isEmpty());//判断字符中有没有内容(不是null)(判断有没有字符)
        System.out.println("bit".length());
    }

    public static void main1(String[] args) {
        String str1 = "abc";

        String str2 = new String("bit");

        char[] array = {'a', 'b', 'c'};
        String str3 = new String(array);

        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
    }
}
